<template>
    <div style="width:100%;height:100%;display:flex;flex-direction: column;">
        <div style="border-left: 5px solid black;padding:10px;width:115px;margin:10px 0;">
            获取软件注册码
        </div>

        <el-form :rules="rules" ref="ruleForm" label-width="110px" :model="softWareForm"
            style="width: 100%;background-color: white;display:flex;flex-direction:column;justify-content:center;align-items: center;flex:1;">
            <el-form-item v-if="pageType == '20' || pageType == '18'" label="软件类型:" prop="softwareType" style="width:410px">
                <el-select v-model="softWareForm.softwareType" @input="updateSearchCondition()" style="width:300px">
                    <el-option v-for="item in softwareTypeArray" :key="item.softKey" :label="item.softwareType" :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item v-if="pageType == '20'" label="查询条件:" prop="searchCondition" style="width:410px">
                <el-select v-model="softWareForm.searchCondition" style="width:300px">
                    <el-option v-for="item in searchConditionArray" :key="item.id" :label="item.content" :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item v-if="pageType == '1'" label="申请说明:" prop="descriptionOfTest" style="width:410px">
                <el-input type="textarea" :rows="2" placeholder="输入测试申请说明" v-model="softWareForm.descriptionOfTest">
                </el-input>
            </el-form-item>
            <el-form-item v-if="pageType == '20'" prop="inputCode" style="width:410px">
                <el-input type="textarea" :rows="2" placeholder="输入二维码ID或机器码进行查询" v-model="softWareForm.searchCode">
                </el-input>
            </el-form-item>
            <el-form-item v-if="pageType == '18'" label="产品型号:" prop="productModel" style="width:410px">
                <el-select v-model="softWareForm.productModel" @input="updateSearchCondition()" style="width:300px">
                    <el-option v-for="item in productModelArray" :key="item.id" :label="item.modelName" :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item v-if="pageType == '18'" label="有效截止日期:"  style="width:410px">
                <el-date-picker v-model="softWareForm.expirationDate" type="date" placeholder="选择日期时间" style="width:200px">
                </el-date-picker>
                <el-checkbox v-model="softWareForm.validForever" style="width:100px;">终身授权</el-checkbox>
            </el-form-item>
            <el-form-item v-if="pageType == '18'" label="序列号:" prop="serialNumber" style="width:410px">
                <el-select v-model="softWareForm.serialNumber" style="width:300px">
                    <el-option v-for="item in serialNumberArray" :key="item" :label="item" :value="item">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item v-if="pageType == '18'" label="机器码:" prop="machineCode" style="width:410px">
                <el-input type="text" autosize placeholder="请输入机器码" v-model="softWareForm.machineCode" style="width:300px">
                </el-input>
            </el-form-item>
            <el-form-item style="width:410px">
                <el-button @click="getRegistrationCode">{{ pageType == '20' ? '查询' : "获取" }}注册码</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import request from "../axios/request";
export default {
    data() {
        return {
            softWareForm: {
                softwareType: null,
                productModel: null,
                serialNumber: null,
                machineCode: null,
                expirationDate: null,
                validForever: false,
                searchCondition: null,
                searchCode: null,
                descriptionOfTest:null
            },
            pageType: null,
            softwareTypeArray: [],
            productModelArray: [],
            serialNumberArray: [],
            rules: {
                softwareType: [
                    { required: true, message: '请选择软件类型', trigger: 'change' }
                ],
                productModel: [
                    { required: true, message: '请选择产品型号', trigger: 'change' }
                ],
                expirationDate: [
                    { required: true, message: '请选择日期', trigger: 'change' }
                ],
                machineCode: [
                    { required: true, message: '请输入机器码', trigger: 'blur' }
                ],
                descriptionOfTest: [
                    { required: true, message: '请输入测试申请说明', trigger: 'blur' }
                ],
                serialNumber: [
                    { required: true, message: '请输入序列号', trigger: 'blur' }
                ],
                searchCondition: [
                    { required: true, message: '请选择查询条件', trigger: 'change' }
                ]
            },
            searchConditionArray: [
                {
                    id: 0,
                    content: "序列号"
                },
                {
                    id: 1,
                    content: "二维码ID"
                }
            ]
        }
    },
    mounted() {
        this.pageType = String(this.$route.params.content);
        this.getSoftwareTypeArray()
        if (this.pageType == '18') {
            this.getProductModelArray()
        }

    },
    methods: {
        async updateSearchCondition() {
            let resOfGetSerialCodeArray = await request({
                url: "/business/api/shipment/GetSerialCodeArray?softKeyId=" + this.softWareForm.softwareType + "&modelId=" + this.softWareForm.productModel,
                method: "GET"
            });
            this.serialNumberArray = resOfGetSerialCodeArray.data.data
        },
        async getSoftwareTypeArray() {
            let resOfGetAllSoftType = await request({
                url: "/business/api/soft/getAllSoftType",
                method: "GET"
            });
            this.softwareTypeArray = resOfGetAllSoftType.data.data
            console.log(this.softwareTypeArray);
        },
        async getProductModelArray() {
            let resOfGetProductModelArray = await request({
                url: "/business/api/productModel/getAllProductModel",
                method: "GET"
            });
            this.productModelArray = resOfGetProductModelArray.data.data
        },
        async getRegistrationCode() {
            let resOfGetRegistrationCode=null
            if (this.pageType == '20') {
                 resOfGetRegistrationCode=await request({
                    url: "/business/api/shipment/getRegistrationCodeBySearch",
                    method: "POST",
                    data:{
                        softwareType:this.softWareForm.softwareType,
                        searchCondition:this.softWareForm.searchCondition,
                        searchCode:this.softWareForm.searchCode
                    }
                });
            } else {
                 resOfGetRegistrationCode = await request({
                    url: "/business/api/shipment/getRegistrationCode",
                    method: "POST",
                    data: this.softWareForm
                });
            }
            console.log(resOfGetRegistrationCode.data.data);
        }
    }
}
</script>

<style scoped></style>